
import { createBrowserRouter, createRoutesFromElements, Route, RouterProvider } from "react-router-dom";
import { Layout, Login } from "./views";
import { Controller } from "./controller";
import zhCN from 'antd/locale/zh_CN';
import React from "react";
import { ConfigProvider } from "@/components/base";
import dayjs from "dayjs";
import isSameOrBefore from 'dayjs/plugin/isSameOrBefore';
import isBetween from 'dayjs/plugin/isBetween';
import isSameOrAfter from 'dayjs/plugin/isSameOrAfter';
import 'dayjs/locale/zh-cn'; // 引入英文语言包
import { decorator } from "./tools/fns/decorator";
import { observer } from "mobx-react";

dayjs.locale('zh-cn');  // 设置语言为中文
dayjs.extend(isSameOrBefore);
dayjs.extend(isBetween);
dayjs.extend(isSameOrAfter);

const App = decorator(observer)(function () {

  const controllers = React.useMemo(() => new Controller(), []);
  const { token } = controllers;

  // 使用组件形式创建路由配置
  const router = createBrowserRouter(
    createRoutesFromElements(
      <Route path="*">
        <Route path="*" element={<Layout />} />
      </Route>
    )
  )

  // 使用组件形式创建路由配置
  const routerLogin = createBrowserRouter(
    createRoutesFromElements(
      <Route path="*">
        <Route path="*" element={<Login />} />
      </Route>
    )
  )

  return (
    <ConfigProvider locale={zhCN}>
      <Controller.Context.Provider value={controllers}>
        <RouterProvider router={token ? router : routerLogin} />
      </Controller.Context.Provider>
    </ConfigProvider>
  )
})
export default App;
